package com.wbk.controller;

import com.wbk.constant.MessageConstant;
import com.wbk.entity.Result;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {

    @RequestMapping("/getUsername")
    public Result getUsername(){
        User user = (User)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        if (user!=null){
            return new Result(true, MessageConstant.GET_USERNAME_SUCCESS,user.getUsername());
        }else {
            return new Result(false,MessageConstant.GET_USERNAME_FAIL);
        }
    }
}
